home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / Printer / src / Xerox_4020 / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  5.0 KB  |  239 lines

  1. /*
  2.     DoSpecial for Xerox_4020 driver.
  3.     David Berezowski - March/88.
  4.  
  5.   Copyright (c) 1988 Commodore-Amiga, Inc.
  6.  
  7.   Executables based on this information may be used in software
  8.   for Commodore Amiga computers.  All other rights reserved.
  9.  
  10.   This information is provided "as is"; no warranties are made.
  11.   All use is at your own risk, and no liability or responsibility is assumed.
  12. */
  13.  
  14.  
  15. #include "exec/types.h"
  16. #include "../printer/printer.h"
  17. #include "../printer/prtbase.h"
  18.  
  19. #define PITCH        4
  20. #define    QUALITY        9
  21. #define INITLEN        16
  22.  
  23. #define TABLEN        34
  24.  
  25. #define PITCHMARG    2
  26. #define LMARG        5
  27. #define RMARG        11
  28. #define MARGLEN        15
  29. /*
  30.     00-02    \033F0        - assure correct pitch        PMARG
  31.     03-08    \033l000\015    - set left margin to '000'    LMARG
  32.     09-14    \033r000\015    - set right margin to '000'    RMARG
  33. */
  34. UBYTE MargBuf[MARGLEN] = "\033F0\033l000\015\033r000\015";
  35. UBYTE pitch;
  36.  
  37. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  38. char outputBuffer[];
  39. UWORD *command;
  40. BYTE *vline;
  41. UBYTE *currentVMI; /* used for color on this printer */
  42. BYTE *crlfFlag;
  43. UBYTE Parms[];
  44. {
  45.     extern struct PrinterData *PD;
  46.  
  47.     int x = 0, y= 0;
  48.     static BYTE ISOcolorTable[10] =
  49.         {49, 51, 53, 52, 55, 50, 54, 48, 49, 49};
  50.     /*       K   R   G   Y   B   M   C   W   K   K */
  51.  
  52.     /*
  53.         00-01    \033R    - underline off
  54.         02-04    \033F0    - 10 cpi            PITCH
  55.         05-06    \033&    - enlarge off
  56.         07-09    \033wb    - nlq off            QUALITY
  57.         10-11    \033s    - super/sub script off
  58.         12-14    \033we    - standard graphics mode
  59.         15-15    \015    - carriage return
  60.     */
  61.     static char initThisPrinter[INITLEN] =
  62.         "\033R\033F0\033&\033wb\033s\033we\015";
  63.     static unsigned char initTabs[TABLEN] =
  64.         "\033i9 17 25 33 41 49 57 65 73 81 89\015";
  65.  
  66.     if (*command == aRIN) {
  67.         while(x < INITLEN) {
  68.             outputBuffer[x] = initThisPrinter[x];
  69.             x++;
  70.         }
  71.         while (y < TABLEN) {
  72.             outputBuffer[x++] = initTabs[y++];
  73.         }
  74.         y = 0;
  75.  
  76.         *currentVMI = 0x70; /* white background, black text */
  77.  
  78.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  79.             outputBuffer[QUALITY] = 'a';
  80.         }
  81.  
  82.         if (PD->pd_Preferences.PrintPitch == PICA) {
  83.             pitch = 10;
  84.             outputBuffer[PITCH] = '0';
  85.         }
  86.         else if (PD->pd_Preferences.PrintPitch == ELITE) {
  87.             pitch = 12;
  88.             outputBuffer[PITCH] = '2';
  89.         }
  90.         else { /* FINE */
  91.             pitch = 17;
  92.             outputBuffer[PITCH] = '4';
  93.         }
  94.  
  95.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  96.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  97.         *command = aSLRM;
  98.     }
  99.  
  100.     if (*command == aCAM) {
  101.         Parms[0] = 1;
  102.         Parms[1] = (95 * 17 + 5) / 10; /* max is 9.5 inches @ 17 cpi */
  103.         *command = aSLRM;
  104.     }
  105.  
  106.     if (*command == aSLRM) {
  107.         CalcMarg(Parms[0], Parms[1]);
  108.         while (y < MARGLEN) {
  109.             outputBuffer[x++] = MargBuf[y++];
  110.         }
  111.         return(x);
  112.     }
  113.  
  114.     /* normal pitch, or elite off, or condensed off, or normal char set */
  115.     if (*command == aSHORP0 || *command == aSHORP1 || *command == aSHORP3
  116.         || *command == aSGR0) {
  117.         pitch = 10;
  118.     }
  119.     else if (*command == aSHORP2) { /* elite on */
  120.         pitch = 12;
  121.     }
  122.     else if (*command == aSHORP4) { /* fine on */
  123.         pitch = 17;
  124.     }
  125.  
  126.     if (*command == aSFC) { /* set foreground/background color */
  127.         if (Parms[0] == 39) {
  128.             Parms[0] = 30; /* set defaults */
  129.         }
  130.         if (Parms[0] == 49) {
  131.             Parms[0] = 47;
  132.         }
  133.         if (Parms[0] < 40) {
  134.             *currentVMI = (*currentVMI & 240) + (Parms[0] - 30);
  135.         }
  136.         else {
  137.             *currentVMI = (*currentVMI & 15) + (Parms[0] - 40) *
  138.                 16;
  139.         }
  140.         outputBuffer[x++] = '\033';
  141.         outputBuffer[x++] = '@';
  142.         outputBuffer[x++] = ISOcolorTable[*currentVMI & 15];
  143.         outputBuffer[x++] = ISOcolorTable[(*currentVMI & 240) / 16];
  144.         return(x);
  145.     }
  146.  
  147.     if (*command == aPLU) {
  148.         if (*vline == 0) {
  149.             *vline = 1;
  150.             *command = aSUS2;
  151.             return(0);
  152.         }
  153.         if (*vline < 0) {
  154.             *vline = 0;
  155.             *command = aSUS3;
  156.             return(0);
  157.         }
  158.         return(-1);
  159.     }
  160.  
  161.     if (*command == aPLD) {
  162.         if (*vline == 0) {
  163.             *vline = -1;
  164.             *command = aSUS4;
  165.             return(0);
  166.         }
  167.         if (*vline > 0) {
  168.             *vline = 0;
  169.             *command = aSUS1;
  170.             return(0);
  171.         }
  172.         return(-1);
  173.     }
  174.  
  175.     if (*command == aSUS0) {
  176.         *vline = 0;
  177.     }
  178.     if (*command == aSUS1) {
  179.         *vline = 0;
  180.     }
  181.     if (*command == aSUS2) {
  182.         *vline = 1;
  183.     }
  184.     if (*command == aSUS3) {
  185.         *vline = 0;
  186.     }
  187.     if (*command == aSUS4) {
  188.         *vline = -1;
  189.     }
  190.  
  191.     if (*command == aRIS) {
  192.         PD->pd_PWaitEnabled = 253;
  193.         pitch = 10;
  194.     }
  195.  
  196.     return(0);
  197. }
  198.  
  199. CalcMarg(left, right)
  200. int left, right;
  201. {
  202.     int i, j, offset, max;
  203.  
  204.     /*
  205.         The minimum left margin on the Xerox_4020 is .5 inches.  Thus
  206.         a left margin of 1 (ie. no left margin) is ...
  207.         5/10 => .5, 6/12 => .5, 8.5/17 => .5
  208.         The maximum print width is 9.5 inches.
  209.     */
  210.     if (pitch == 10) { /* PICA */
  211.         MargBuf[PITCHMARG] = '0';
  212.         offset = 40;
  213.         max = (95 * 10 + 5) / 10;
  214.     }
  215.     else if (pitch == 12) { /* ELITE */
  216.         MargBuf[PITCHMARG] = '2';
  217.         offset = 50;
  218.         max = (95 * 12 + 5) / 10;
  219.     }
  220.     else { /* FINE */
  221.         MargBuf[PITCHMARG] = '4';
  222.         offset = 75;
  223.         max = (95 * 17 + 5) / 10;
  224.     }
  225.     if ((i = (left * 10 + offset + 5) / 10) > max) {
  226.         i = max;
  227.     }
  228.     MargBuf[LMARG] = ((i % 1000) / 100) + '0';
  229.     MargBuf[LMARG + 1] = ((i % 100) / 10) + '0';
  230.     MargBuf[LMARG + 2] = (i % 10) + '0';
  231.     if ((i = (right * 10 + offset + 15) / 10) > max) {
  232.         i = max;
  233.     }
  234.     MargBuf[RMARG] = ((i % 1000) / 100) + '0';
  235.     MargBuf[RMARG + 1] = ((i % 100) / 10) + '0';
  236.     MargBuf[RMARG + 2] = (i % 10) + '0';
  237.     return(MARGLEN);
  238. }
  239.